import { VuexModule, Module, Mutation, Action, getModule } from 'vuex-module-decorators'
import store from '@/store'

export interface IPageFiliter {
  commonTablePageFiliter: any;
}

@Module({ dynamic: true, store, name: 'pageFiliter' })
class PageFiliter extends VuexModule implements IPageFiliter {
  public commonTablePageFiliter: any = JSON.parse(window.localStorage.getItem('commonTablePageFiliter') || '{}');

  @Mutation
  private CHANGE_COMMON_TABLE_PAGE_FILITER(tableFiliter: any) {
    this.commonTablePageFiliter[tableFiliter.key] = tableFiliter.option;
    window.localStorage.setItem('commonTablePageFiliter', JSON.stringify(this.commonTablePageFiliter));
  }

  @Action
  public changeCommonTablePageFiliter(tableFiliter: any) {
    this.CHANGE_COMMON_TABLE_PAGE_FILITER(tableFiliter);
  }
}

export const PageFiliterModule = getModule(PageFiliter)
